package com.ugoodtech.mdcc.client;

        /* Copyright (C) Ugoodtech, Inc - All Rights Reserved.
         * Unauthorized copying of this file, via any medium is strictly prohibited.
         * Proprietary and confidential.
         * Written by Stone Shaw.
         */

import org.apache.tomcat.jdbc.pool.ConnectionPool;
import org.apache.tomcat.jdbc.pool.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

//    @Autowired
//    private DataSource dataSource;

    @Bean
    public Docket api() throws SQLException {
//        ConnectionPool pool = dataSource.getPool();
////                System.out.println(pool.getActive());
//        Connection conn = pool.getConnection();
////                System.out.println(pool.getActive());
//
//        PreparedStatement ps = conn.prepareStatement("select token from oauth_access_token");
//        ResultSet resultSet=ps.executeQuery();
//        String token=resultSet.getString(0);
//        conn.close();
////        System.out.println("reset access_token for username:" + username);
        String auth = "Bearer " + "ff6ba5f4-e0df-40b1-8e93-860bc6083f68";
        ParameterBuilder aParameterBuilder = new ParameterBuilder();
        aParameterBuilder.name("Authorization").defaultValue(auth).description("token").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        ParameterBuilder aParameterBuilder2 = new ParameterBuilder();
        aParameterBuilder2.name("Accept").defaultValue("application/json").description("固定参数").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        List<Parameter> aParameters = new ArrayList<Parameter>();
        aParameters.add(aParameterBuilder.build());
        aParameters.add(aParameterBuilder2.build());
        return new Docket(DocumentationType.SWAGGER_2)
                .globalOperationParameters(aParameters)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        ApiInfo apiInfo = new ApiInfo(
                "漆星应用h5API",
                "漆星应用h5API的说明",
                "2.0.0",
                "Terms of service",
                "kotone.tang@ugoodtech.com",
                "License of API",
                "API license URL");
        return apiInfo;
    }
}
